package com.ruoyi.web.controller.custom;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.custom.domain.TbBack;
import com.ruoyi.custom.service.ITbBackService;

/**
 * 客户回款Controller
 *
 * @author ruoyi
 * @date 2025-07-25
 */
@Api(tags = "客户回款")
@RestController
@RequestMapping("/custom/back")
public class TbBackController extends BaseController
{
    @Autowired
    private ITbBackService tbBackService;

    /**
     * 查询客户回款列表
     */
    @ApiOperation("查询客户回款列表分页")
    @PreAuthorize("@ss.hasPermi('custom:back:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbBack tbBack)
    {
        startPage();
        List<TbBack> list = tbBackService.selectTbBackList(tbBack);
        return getDataTable(list);
    }

    /**
     * 导出客户回款列表
     */
    @PreAuthorize("@ss.hasPermi('custom:back:export')")
    @Log(title = "客户回款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,TbBack tbBack)
    {
        List<TbBack> list = tbBackService.selectTbBackList(tbBack);
        ExcelUtil<TbBack> util = new ExcelUtil<TbBack>(TbBack.class);
         util.exportExcel(response,list, "回款数据");
    }

    /**
     * 获取客户回款详细信息
     */
    @ApiOperation("获取客户回款详细信息")
    @PreAuthorize("@ss.hasPermi('custom:back:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbBackService.selectTbBackById(id));
    }

    /**
     * 新增客户回款
     */
    @ApiOperation("新增客户回款")
    @PreAuthorize("@ss.hasPermi('custom:back:add')")
    @Log(title = "客户回款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbBack tbBack)
    {
        return toAjax(tbBackService.insertTbBack(tbBack));
    }

    /**
     * 修改客户回款
     */
    @ApiOperation("修改客户回款")
    @PreAuthorize("@ss.hasPermi('custom:back:edit')")
    @Log(title = "客户回款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbBack tbBack)
    {
        return toAjax(tbBackService.updateTbBack(tbBack));
    }

    /**
     * 删除客户回款
     */
    @ApiOperation("删除客户回款")
    @PreAuthorize("@ss.hasPermi('custom:back:remove')")
    @Log(title = "客户回款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbBackService.deleteTbBackByIds(ids));
    }

    @ApiOperation("业务员回款佣金排行")
    @GetMapping(value = "/getRateMoney")
    public AjaxResult getRateMoney()
    {
        return AjaxResult.success(tbBackService.getRateMoneyRank());
    }

    @ApiOperation("本月团队排行")
    @GetMapping(value = "/getDeptRateMoney")
    public AjaxResult getDeptRateMoney()
    {
        return AjaxResult.success(tbBackService.getDeptRateMoneyRank());
    }
}
